/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package image.edge;

import image.filter.Filter;
import image.processing.ImageProcessor.CompressAlgorithm;
import image.utils.ImageUtilities;
import image.utils.ImageUtilitiesImpl;
import java.awt.image.BufferedImage;

/**
 *
 * @author tommy
 */
public abstract class EdgeDetectorImpl implements EdgeDetector {
	BufferedImage src;
	BufferedImage ret;
	
	public EdgeDetectorImpl(BufferedImage src, Filter filter) {
		src = filter.applyFilter(src, CompressAlgorithm.LINEAR);
		ImageUtilities img = ImageUtilitiesImpl.getInstance();
		ret = ImageUtilitiesImpl.getInstance().blackImage(src.getWidth(), src.getHeight());
		
		if (src.getType() == BufferedImage.TYPE_3BYTE_BGR || 
			src.getType() == BufferedImage.TYPE_4BYTE_ABGR) {
			src = img.toGrayScale(src);
		}
		
		this.src = img.addPaddingEdge(src, 1);
	}
	
	public EdgeDetectorImpl (BufferedImage src) {
		this(src,1);
	}
	
	// for n paddingEdge size
	public EdgeDetectorImpl(BufferedImage src, int n) {
		ImageUtilities img = ImageUtilitiesImpl.getInstance();
		ret = ImageUtilitiesImpl.getInstance().blackImage(src.getWidth(), src.getHeight());
		
		if (src.getType() == BufferedImage.TYPE_3BYTE_BGR || 
			src.getType() == BufferedImage.TYPE_4BYTE_ABGR || 
			src.getType() == BufferedImage.TYPE_BYTE_INDEXED) {
			src = img.toGrayScale(src);
		}
		
		this.src = img.addPaddingEdge(src, n);
	}
}
